package com.wanmait.hotelManage.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.wanmait.hotelManage.util.DBHelper;
import com.wanmait.hotelManage.vo.Price;

public class PriceDAO {
	private PriceDAO () {}
	private static PriceDAO priceDAO=new PriceDAO();
	public static PriceDAO getdao() {
		return priceDAO;
	}
	public List<Price> findAll() {
		// TODO Auto-generated method stub
		List<Price> prices=new ArrayList<Price>();
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select * from price where enable=1";
		
		try {
			conn=DBHelper.getDBHelper().getConn();
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()) {
				Price price=new Price();
				price.setId(rs.getInt("id"));
				price.setMax(rs.getInt("max"));
				price.setMin(rs.getInt("min"));
				prices.add(price);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DBHelper.getDBHelper().close(rs, ps, conn);
		}
		
		return prices;
	}
	
	
	
}
